using FrameWork;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EventComponent : BaseComponent
{
    private IEventManager eventManager;

    public override void Awake()
    {
        base.Awake();
        eventManager = new EventManager();
        //var t = Type.GetType("EventManager");
        //eventManager = (IEventManager)Activator.CreateInstance(t);
    }

    /// <summary>
    /// 订阅
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="handler"></param>
    public void Register<T>(EventHandler<GameEventArgs> handler) where T : GameEventArgs
    {
        eventManager.Register<T>(handler);
    }


    /// <summary>
    /// 取消订阅
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="handler"></param>
    public void UnRegister<T>(EventHandler<GameEventArgs> handler) where T : GameEventArgs
    {
        eventManager.UnRegister<T>(handler);
    }
    /// <summary>
    /// 发送事件
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="sender"></param>
    /// <param name="args"></param>
    public void Fire<T>(object sender, GameEventArgs args) where T : GameEventArgs
    {
        eventManager.Fire<T>(sender, args);
    }

}
